<?php
class Screenshot
{
    /**
     * The adapter to use specified in the config file
     */
    protected $_adapter;
    
    /**
     * Sets up the adapter for use in the class
     */
    public function __construct()
    {
        $config = Zend_Registry::get('config');
        
        if (!isset($config->app->thumbnail->adapter)) {
            return null;
        }
        
        $options = array();
        
        foreach ($config->app->thumbnail->options as $key => $value) {
            $options[$key] = $value;
        }
        
        $classname = 'Screenshot_Adapter_' . $config->app->thumbnail->adapter;
        
        $rc = new ReflectionClass($classname);
        
        $this->_adapter = new $classname($options);
        
        if (!($this->_adapter instanceof Screenshot_Adapter_Interface)) {
            return null;
        }    
    }
    
    public function capture($url, $width, $height)
    {
        return $this->_adapter->generateScreenshot($url, $width, $height);
    }
    
    public function getDimensions($size)
    {
        return $this->_adapter->getDimensions($size);
    } 
}